/**
 * Created by KhoaNam on 7/12/2014.
 */
var MySprite = cc.Sprite.extend({
    ctor: function(){
        this._super();
        this.enableEvent = true;
        this.isTap = false;
        this.isMouseOver = false;
    },

    init: function(){
        this._super();
    },

    setImage: function(src){
        var texture = cc.TextureCache.getInstance().textureForKey(src);
        this.setTexture(texture);
    },

    moveTo: function(duration, pos, callback){
        var move = cc.MoveTo.create(duration, cc.p(pos.x, pos.y));
        var action = cc.Sequence.create(move);
        action.onFinished = function(target){
            callback(target);
        };
        this.runAction(action);
    },

    moveBy: function(duration, pos, callback){
        var move = cc.MoveTo.create(duration, cc.p(this.getPositionX() + pos.x, this.getPositionY() + pos.y));
        var action = cc.Sequence.create(move);
        action.onFinished = function(target){
            callback(target);
        };
        this.runAction(action);
    },

    onTouchBegan: function(touch, event){
        this.isTap = true;
    },

    onTouchEnded: function(touch, event){
        if(this.isTap){
            this._onTap(touch, event);
        }
    },

    onTouchMoved: function(touch, event){
        this.isTap = false;
    },

    onTouchCancelled: function(touch, event){
        this.isTap = false;
    },

    onTap: function(touch, event){

    },

    _onTap: function(touch, event){
        this.onTap(touch, event);
    },

    _onMouseOver: function(mouse, event){
        this.onMouseOver(mouse, event);
    },

    onMouseOver: function(mouse, event){

    },

    _onMouseOut: function(mouse, event){
        this.onMouseOut(mouse, event);
    },

    onMouseOut: function(mouse, event){

    }
});